const express = require('express')
const cors = require('cors')
const pool = require('./mysql/mysql')
const bodyPaser = require ('body-parser')
const common = require('./router/common/index')
const private = require('./router/private/index')
const dispark = require('./router/dispark/index')
const user = require('./router/user/index')
// const Nodetoken = require('./token/token')

const server = express()
pool.connect(err=>{
  if(err)throw err;
  console.log('数据库连接成功')
})
//所有都可以访问
server.use(cors({origin:'*'}))

//中间件
server.use(bodyPaser.urlencoded({extended:false}))
server.use(bodyPaser.json())

/*
路由拦截
请求公共的不管
请求private的进行token验证
*/
server.use((req,res,next)=>{
  next()
})
//登录或者注册
server.use('/user',user)

//静态资源
server.use('/common', common);

//私有
server.use('/private', private);

//公共
server.use('/dispark', dispark);
server.listen(4040,()=>{
  console.log('监听端口4040')
})